package ChaiPiao;

import java.util.ArrayList;
import java.util.List;

public class Ticket {
    private List<List<PlayTypeValuesEnumeration>> combination;
    private List<PlayTypeValuesEnumeration> list;
    private int noteCount;

    public Ticket() {
        this.list = new ArrayList<>();
        this.combination = new ArrayList<>();
    }

    public int getNoteCount() {
        return noteCount;
    }

    public void addPlayTypeValuesEnumeration(PlayTypeValuesEnumeration enumeration) {
        this.list.add(enumeration);
        flushCount();
    }

    public void addPlayTypeValuesCombination(List<PlayTypeValuesEnumeration> combination) {
        this.combination.add(combination);
        flushCount();
    }

    private void flushCount() {
        int count = 0;
        for (List<PlayTypeValuesEnumeration> enumerations : this.combination) {
            int c = 1;
            for (PlayTypeValuesEnumeration enumeration : enumerations) {
                c *= enumeration.valueCount();
            }
            count += c;
        }
        this.noteCount = count;
    }

    @Override
    public String toString() {
        String split = "|";
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < this.list.size(); i++) {
            if (i == this.list.size() - 1)
                split = "";
            stringBuffer.append(this.list.get(i)).append(split);
        }
        return stringBuffer.toString() + "@" + noteCount;
    }
}
